<?php
namespace RMD\AccountBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

use RMD\AccountBundle\Entity\GroupSet;
use RMD\AccountBundle\Form\DataTransformer\TestTransformer;

class ListSegmentType extends AbstractType
{
	public function __construct() {

	}

	public function buildForm(FormBuilderInterface $builder, array $options) {
		if (isset($options['data'])) {
			$lists = $options['data'];
			$choices = array();
			foreach ($lists as $list) {
				$choices[$list->getId()] = $list->getTitle();
			}
			$builder->add('lists', 'choice', array(
					'choices'   => $choices,
					'multiple' => false,
					//'mapped' => false,
					'required' => true,
					'expanded' => true,
					'label' => '',
					//'data' => $data
					)
				);
		}
		if (isset($options['segmentOptions'])) {
			$segmentOptions = $options['segmentOptions'];
			$choices = array();
			foreach ($segmentOptions as $field => $segment) {
				$choices[$field] = $segment['Title'];
			}
			$builder->add('field', 'choice', array(
				'choices'   => $choices,
				'required'  => true,
			));
		}
		if (isset($options['operations'])) {
			$operations = $options['operations'];
			$choices = array();
			foreach ($operations['statements'] as $key => $operation) {
				$choices[$key] = $operation;
			}
			$builder->add('operation', 'choice', array(
				'choices'   => $choices,
				'required'  => true,
			));
		}
	}

    public function getName() {
        return 'listSegment';
    }
    /*public function getDefaultOptions(array $options)
    {

    }*/
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => null,//'RMD\AccountBundle\Entity\Lists',
            'intention'       => 'listSegment_item'
        ));
		$resolver->setOptional(array('operations', 'segmentOptions'));
    }
}
?>
